var mongo = require('mongodb');
 
var Server = mongo.Server,
    Db = mongo.Db,
    BSON = mongo.BSONPure;
 
var server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('avicultorDB', server);
 
db.open(function(err, db) {
    if(!err) {
        console.log("Connected to 'avicultoresdb' database");/*
        db.collection('wines', {strict:true}, function(err, collection) {
            if (err) {
                console.log("The 'avicultoresdb' collection doesn't exist. Creating it with sample data...");
                //populateDB();
            }
        });*/
    }
});






exports.listaPuntosFiltro = function(filtro,callback){

        db.collection('avicultoresFormulario', function(err, collection) {
        collection.find(filtro).toArray(function(err, items) {
        
             if (err) {
				callback(false, null);
                //res.send({'error':'An error has occurred'});
            } else {
                console.log('Success: ' + JSON.stringify(items));
                callback(true, items);
                //res.send(result[0]);
            }
        
            //res.send(items);
        });
    });
    
};



exports.listaPuntos = function(callback){

        db.collection('avicultoresFormulario', function(err, collection) {
        collection.find().toArray(function(err, items) {
        
             if (err) {
				callback(false, null);
                //res.send({'error':'An error has occurred'});
            } else {
                console.log('Success: ' + JSON.stringify(items));
                callback(true, items);
                //res.send(result[0]);
            }
        
            //res.send(items);
        });
    });
    
};





exports.obtenerPunto = function(id,callback){

        db.collection('avicultoresImagenes', function(err, collection) {
        collection.find({'idFormulario':id}).toArray(function(err, items) {
        
             if (err) {
				callback(false, null);
                //res.send({'error':'An error has occurred'});
            } else {
                console.log('Success: ' + JSON.stringify(items));
                callback(true, items);
                //res.send(result[0]);
            }
        
            //res.send(items);
        });
    });
    
};
